package com.zhuang.designpattern.responsibility;

import com.alibaba.fastjson.*;
import com.zhuang.designpattern.responsibility.impl.Level1AuthLink;
import com.zhuang.designpattern.responsibility.impl.Level2AuthLink;
import com.zhuang.designpattern.responsibility.impl.Level3AuthLink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.util.Date;

/**
 * description: Test
 * date: 2022/9/19 9:35
 * author: Zhuang
 * version: 1.0
 */
public class Test {
    private static final String ORDERID = "1000998004813441";

    public static void main(String[] args) throws ParseException {

        Logger logger = LoggerFactory.getLogger(Test.class);
        AuthLink authLink = new Level3AuthLink("1000013", "王工")
                .appendNext(new Level2AuthLink("1000012", "张经理")
                        .appendNext(new Level1AuthLink("1000011", "段总")));

        logger.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("康小庄", ORDERID, new Date())));
        // 模拟三级负责人审批
        AuthService.auth("1000013", ORDERID);
        logger.info("测试结果：{}", "模拟三级负责人审批，王工");
        logger.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("康小庄", ORDERID, new Date())));
        // 模拟二级负责人审批
        AuthService.auth("1000012", ORDERID);
        logger.info("测试结果：{}", "模拟二级负责人审批，张经理");
        logger.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("康小庄", ORDERID, new Date())));
        // 模拟一级负责人审批
        AuthService.auth("1000011", ORDERID);
        logger.info("测试结果：{}", "模拟一级负责人审批，段总");
        logger.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("康小庄", ORDERID, new Date())));

    }
}
